<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input v-model="listQuery.topic" clearable class="filter-item" style="width: 200px;" placeholder="请输入话题名称"/>
      <el-input v-model="listQuery.period" clearable class="filter-item" style="width: 200px;" placeholder="请输入播出期数"/>
      <el-button class="filter-item" icon="el-icon-search" @click="handleFilter">查找</el-button>
      <!--      <el-button class="filter-item" icon="el-icon-download">下载所有</el-button>-->
    </div>
    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>
      <el-table-column align="center" label="直播话题" prop="topic"/>
      <el-table-column align="center" label="播出期数" prop="period"/>
      <el-table-column align="center" label="M3U8地址" prop="hls_url"/>
      <el-table-column align="center" label="播出时间" prop="day"/>

      <el-table-column align="center" label="操作" width="100" class-name="small-padding">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleCreateClip(scope.row)">创建剪辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>
<script>

import BackToTop from '../../../components/BackToTop'
import Pagination from '../../../components/Pagination'
import ObjectUtil from '../../../utils/object-util'
import { apiCbct } from '../../../api/cbct/cbct'
import { ClipVideoTypeContants } from '../../../mixin/MixinContants'
import { apiVideo } from '../../../api/clip/task'

export default {
  name: 'RadioProgramPlayList',
  components: { BackToTop, Pagination },
  mixins: [
    ClipVideoTypeContants.mixin
  ],
  props: {
    programmeId: {
      type: String,
      default: undefined
    },
    programmeInfo: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 100,
        id: undefined,
        topic: undefined,
        period: undefined,
        sort: 'add_time',
        order: 'desc'
      }
    }
  },
  created() {
    this.Init()
  },
  methods: {
    getNewStatus(status) {
      return (status + 1) % 2
    },
    Init() {
      this.getList()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    getList() {
      this.listLoading = true
      apiCbct.getProgrammePlayList({ ...this.listQuery, programmeId: this.programmeId }).then(res => {
        const resList = res.data.data.list || []
        this.list = resList.filter(t => ObjectUtil.notNull(t))
      }).finally(() => {
        this.listLoading = false
      })
    },
    handleCreateClip(row) {
      const videoInfo = {
        sourceType: this.ClipVideoTypeContants.m3u8.key,
        meterialType: 1,
        title: row.topic + '_' + this.programmeInfo.title + '_' + this.programmeInfo.channel_name + '_' + this.programmeInfo.channel_code + '_' + this.programmeInfo.radio_name + '_' + this.programmeInfo.number + '_' + row.period,
        progCode: this.programmeId,
        stationName: this.programmeInfo.radio_name,
        sourceUrl: row.hls_url,
        meta: JSON.stringify({ ...this.programmeInfo, ...row })
      }
      console.log(videoInfo)
      apiVideo.createByCbct(videoInfo)
        .then(response => {
          this.dialogFormVisible = false
          this.$notify.success({
            title: '成功',
            message: '创建成功'
          })
        })
        .catch(response => {
          this.$notify.error({
            title: '失败',
            message: (response.data || {})['errmsg'] || '请联系系统管理员'
          })
        })
    }
  }
}
</script>

<style scoped>

</style>
